﻿/*++

Copyright (c) 2011 Rainr Corporation

Module Name:

	Rainr.Utilities.Common.RandomUtility

Abstract:

	随机数工具类

Author:

	Zhou Junyu (Rainr)    2011-01-01

Revision History:
  
--*/

using System;
using System.Collections.Generic;
using System.Text;

namespace Rainr.Utilities.Common
{
    /// <summary>
    /// 随机数工具类
    /// </summary>
    public sealed class RandomUtility
    {
        #region 静态成员
        public static int Next(int minValue, int maxValue)
        {
            return CurrentRandomEx.Next(minValue, maxValue);
        }
        /// <summary>
        /// 返回一个小于所指定最大值的非负随机数。
        /// </summary>
        /// <param name="maxValue">要生成的随机数的上界（随机数不能取该上界值）。maxValue 必须大于等于零。</param>
        /// <returns></returns>
        public static int Next(int maxValue)
        {
            return CurrentRandomEx.Next(maxValue);
        }
        /// <summary>
        /// 返回非负随机数。
        /// </summary>
        /// <returns>大于等于零且小于 System.Int32.MaxValue 的 32 位带符号整数。</returns>
        public static int Next()
        {
            return CurrentRandomEx.Next();
        }

        /// <summary>
        /// 返回一个大于等于0.0且小于1.0的随机小数点1位小数
        /// </summary>
        /// <returns></returns>
        public static double NextDouble()
        {
            return CurrentRandomEx.NextDouble();
        }

        /// <summary>
        /// 返回一个随机的定长字节数组
        /// </summary>
        /// <param name="byteLenght">数组的长度</param>
        /// <returns>字节数组</returns>
        public static byte[] NextBytes(uint byteLenght)
        {
            return CurrentRandomEx.NextBytes(byteLenght);
        }

        public static RandomEx CurrentRandomEx
        {
            get
            {
                if (null == currentRandomEx) currentRandomEx = new RandomEx();
                return currentRandomEx;
            }
        }
        private static RandomEx currentRandomEx;
        #endregion

    }
}